﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace CCM.CronTaskScheduler {
    public interface INotificationProvider {
        void AddRunCompleteHandler(Action<TaskRunResult> handler);
        void RunComplete(TaskRunResult result);
    }

    public class NotificationProvider : INotificationProvider {
        private static List<Action<TaskRunResult>> runCompleteHandlers = new List<Action<TaskRunResult>>();
        private static object handlerLock = new object();


        public void AddRunCompleteHandler(Action<TaskRunResult> handler) {
            lock (handlerLock) {
                runCompleteHandlers.Add(handler);
            }
        }


        public void RunComplete(TaskRunResult result) {
            runCompleteHandlers.ForEach(h => h(result));
        }


    }
}
